import { AddNode, AssignNode, ExprNode, IntNode, MultNode, PrintNode, PrintVisitor, StatListNode, StatNode, VarNode, VectorNode } from ".";
import { Token } from ".";

function I(i:number){
    return new IntNode(new Token(Token.INT,i+""))
}

// 构建语法树
let stats: StatNode[] = [];
// x = 3 + 4
let a:AddNode = new AddNode(I(3),new Token(Token.PLUS),I(4));
let x:VarNode = new VarNode(new Token(Token.ID,"x"));
let assign:AssignNode = new AssignNode(x,new Token(Token.ASSIGN,"="),a);

//print x * [2,3,4]
let mult = new Token(Token.MULT,"*");
let elements:ExprNode[] = [];
elements.push(I(2));
elements.push(I(3));
elements.push(I(4));
let v = new VectorNode(new Token(Token.VEC),elements);
let xref = new VarNode(new Token(Token.ID,"x"));
let pv = new MultNode(xref,mult,v);
let p = new PrintNode(new Token(Token.PRINT,"print"),pv);

stats.push(p);
let statList = new StatListNode(stats);

//创建访问器
// 设计模式 访问器模式
// 内嵌式 astNode.print()
// 访问者 visitor.print(astNode)
let visitor = new PrintVisitor();
statList.visit(visitor);


